//index.js
//获取应用实例
const app = getApp()

Page({
	data: {
		judge: '',
		http: getApp().globalData.map,
		user: {'uid': ''},
		motto: 'Hello World',
		userInfo: {},
		hasUserInfo: false,
		canIUse: wx.canIUse('button.open-type.getUserInfo'),
		state:false,
	},
	xin(){
		wx.navigateTo({
			url:'xin/xin'
		})
	},
	nav(en){
		wx.request({
			url: getApp().globalData.http + 'action=applySearch&uid=' + this.data.user.uid,
			success:(e)=>{
				console.log(e)
				let changjia=e.data.data.changjia
				let jishi=e.data.data.jishi
				let xiulichang=e.data.data.xiulichang
				let a=en.currentTarget.dataset.id
				console.log(a)
				if(a==4){
					wx.navigateTo({
						url:'../special/special'
					})
				}else{
						if(a==1){
							console.log(changjia)
							if(changjia==3&&jishi==3&&xiulichang==3){
								wx.navigateTo({
									url:'../check/shop/shop?id=1'
								})
							}else if(changjia==0){
								wx.switchTab({
									url:'../check/audit/audit'
								})
							}else if(changjia==1){
								wx.switchTab({
									url:'../check/check'
								})
							}else if(changjia==2){
								wx.navigateTo({
									url:'../check/defeated/defeated?id=1'
								})
							}else if(jishi==0||jishi==1){
								wx.showToast({
									title:'您已提交其他申请',
									icon:'none'
								})
							}else if(xiulichang==0||xiulichang==1){
								wx.showToast({
									title:'您已提交其他申请',
									icon:'none'
								})
							}
						}else if(a==2){
							if(changjia==3&&jishi==3&&xiulichang==3){
								wx.navigateTo({
									url:'../check/jishi/jishi?id=2'
								})
							}else if(jishi==0){
								wx.navigateTo({
									url:'../check/audit/audit'
								})
							}else if(jishi==1){
								wx.switchTab({
									url:'../check/check'
								})
							}else if(jishi==2){
								wx.navigateTo({
									url:'../check/defeated/defeated?id=2'
								})
							}else if(changjia==0||changjia==1){
								wx.showToast({
									title:'您已提交其他申请',
									icon:'none'
								})
							}else if(xiulichang==0||xiulichang==1){
								wx.showToast({
									title:'您已提交其他申请',
									icon:'none'
								})
							}
						}else if(a==3){
							if(changjia==3&&jishi==3&&xiulichang==3){
								wx.navigateTo({
									url:'../check/gysenter/gysenter?id=3'
								})
							}else if(xiulichang==0){
								wx.navigateTo({
									url:'../check/audit/audit?id=3'
								})
							}else if(xiulichang==1){
								wx.switchTab({
									url:'../check/check'
								})
							}else if(xiulichang==2){
								wx.switchTab({
									url:'../check/defeated/defeated?id=3'
								}) 
							}else if(changjia==0||changjia==1){
								wx.showToast({
									title:'您已提交其他申请',
									icon:'none'
								})
							}else if(jishi==0||jishi==1){ 
								wx.showToast({
									title:'您已提交其他申请',
									icon:'none'
								})
							}
						}else if(a==4){
							wx.navigateTo({
								url:'../special/special'
							})
						}else if(a==5){
							wx.navigateTo({
								url:'../strict/strict'
							})
						}else if(a==6){
							wx.navigateTo({
								url:'mxzc/mxzc?id='+en.currentTarget.dataset.index
							})
						}else if(a==7){
							wx.navigateTo({
								url:'../goods/goods?id='+en.currentTarget.dataset.index
							})
						}else if(a==8){
							wx.navigateTo({
								url:'../activity/activity?id='+en.currentTarget.dataset.index
							})
						}
				}
			}
		})
	},
	onShow: function() {
		wx.getStorage({
			key:'car',
			success:(e)=>{
				if(e.data!=''){
					this.setData({
						isMr:e.data[0].isMr,
						car:e.data
					})
					console.log(e)
				}
			}
		})
		wx.getStorage({
			key: 'uid',
			success: (res) => {
				if (res.data.Vip == '1') {
					this.setData({
						judge: '赚'
					})
				}
				this.setData({
					user: res.data
				})
			},
			complete: () => {
				wx.request({
					url: getApp().globalData.http + 'action=xcxIndex&uid=' + this.data.user.uid,
					success: (e) => {
						console.log(e)
						e.data.data.guanggao.forEach(function(item, index) {
							item.LinkUrl=item.LinkUrl.split('=')
						})
						if (e.data.code == 1) {
							this.setData({
								title: e.data.data
							})
						}
					}
				})
			}
		})
	},
	getScancode: function() {
		var _this = this;
		// 允许从相机和相册扫码
		wx.scanCode({
			success: (res) => {
				console.log(res)
				if (isNaN(res.result)) {
					wx.showToast({
						icon: 'none',
						title: '二维码错误'
					})
				} else {
					wx.request({
						url: getApp().globalData.http1 + 'action=gzShop&uid=' + _this.data.user.uid + '&shopID=' + res.result,
						success: (e) => {
							console.log(e)
							wx.showToast({
								icon: 'none',
								title: e.data.msg
							})
							this.setData({
								sc: !(this.data.sc)
							})
						}
					})
				}
			}
		})
	},
	wkf(){
		wx.navigateTo({
			url:'../kong/kong'
		})
	},
	list(e){
		let a=e.currentTarget.dataset.id
		let b=''
		if(a==1){
			b='../cell/cell'
		}else if(a==2){
			b='../brand/brand'
		}else if(a==3){
			b='../share/share'
		}else if(a==4){
			b='../rescue/rescue'
		}else if(a==5){
			b='../city/new/new'
		}else if(a==6){
			b='../share/share'
		}else if(a==7){
			b='../chexian/chexian'
		}else if(a==8){
			b='../direct/direct'
		}else if(a==9){
			b='../ticket/ticket'
		}else if(a==10){
			b='../sign/sign'
			// this.wkf()
		}else{
			b=''
			this.wkf()
		}
		wx.navigateTo({
			url:b
		})
	},
	none(){
		this.setData({
			state:false
		})
	},
	goin(){
		this.setData({
			state:false
		})
		wx.navigateTo({
			url:'xin/xin'
		})
	},
	onLoad(query){
		 wx.getSystemInfo({
		      success: e => {
				  console.log(e.statusBarHeight) //状态栏高度
		        let custom = wx.getMenuButtonBoundingClientRect();//菜单按钮
				console.log(custom)
				console.log(custom.bottom + custom.top - e.statusBarHeight)
				let a=custom.bottom + custom.top - e.statusBarHeight
				this.setData({
					gap:custom
				})
		        //计算得到定义的状态栏高度
		      }
		    })
		if(query.state!=undefined){
			this.setData({
				state:true
			})
		}
		const scene = decodeURIComponent(query.scene);
		if (scene!='undefined') {
			console.log("scene is ", scene);
			var arrPara = scene.split(",");
			var arr = [];
			console.log(arrPara)
			wx.redirectTo({
				url:'../goods/goods?id='+arrPara[1]
			})
			wx.request({
				url: getApp().globalData.http + 'action=setTjr&tjr=' + arrPara[0],
				success: (e) => {
					console.log(e)
					wx.setStorage({
						key:'tjrid',
						data:e.data.data.code
					})
				}
			})
			this.setData({
				tjr: e.tjr
			})
		}
	},
	gotoc(e){
		console.log(e)
		let a=e.currentTarget.dataset.name
		let c=e.currentTarget.dataset.id
		if(a=='itemId'){
			let nan={'currentTarget':{'dataset':{'id':c}}}
			this.list(nan)
		}else if(a=='goodsId'){
			wx.navigateTo({
				url:'../goods/goods?id='+c
			})
		}else if(a=='classId'){
			wx.navigateTo({
				url:'mxzc/mxzc?id='+c
			})
		}else if(a=='wnzb'){
			wx.navigateTo({
				url:'activity/activity?id='+c
			})
		}else if(a=='xlcId'){
			wx.navigateTo({
				url:'../city/li-city/li-city?id='+c
			})
		}else if(a=='gysId'){
			wx.navigateTo({
				url:'../goods/store/store?id='+c
			})
		}else if(a=='cqsjx'){
			wx.navigateTo({
				url:'../strict/strict?id='+c
			})
		}else if(a=='temai'){
			wx.navigateTo({
				url:'../special/special?id='+c
			})
		}else if(a=='xrlb'){
			wx.navigateTo({
				url:'xin/xin?id='+c
			})
		}else if(a=='bwl'){
			wx.navigateTo({
				url:'../bwl/bwl?id='+c
			})
		}else if(a=='mxzc'){
			wx.navigateTo({
				url:'../mxzc/mxzc?id='+c
			})
		}else if(a=='mxzc'){
			wx.navigateTo({
				url:'../mxzc/mxzc?id='+c
			})
		}
	}
})
